package demo1;

public class Test2 {
    public static void main(String[] args) {
        //区分大小写
        String s = "dBowNgxyPZXZXlBTMKFskExQEK";

        //用来拼接不一样的字符
        StringBuilder stringBuilder = new StringBuilder();
        int[] nums1 = new int[26]; //默认都是0   存大写字符个数
        int[] nums2 = new int[26];//默认都是0    存小写字符个数


        //将每个字符出现的次数放入nums数组中
        for (int i = 0; i < s.length(); i++) {
            if (isCase(s.charAt(i)) == -1) {
                nums1[s.charAt(i) - 65]++;
            } else {
                nums2[s.charAt(i) - 97]++;
            }
        }

        //无序输出  (输出没有重复的字符 (从存到数组中的个数判断))
        //将只出现了一次的字母拼接起来
        for (int i = 0; i < s.length(); i++) {
            if (nums1[i] == 1) {
                stringBuilder.append((char)(i+97));
            }
            if (nums2[i] == 1) {
                stringBuilder.append((char)(i+65));
            }
        }


        //有序输出  (按照字符输入的顺序输出 (从0下标开始判断字符))
        StringBuilder stringBuilder1 = new StringBuilder();
        for (int i = 0; i < s.length(); i++) {
            if (isCase(s.charAt(i)) == 1) {
                if (nums2[s.charAt(i) - 97] == 1) {
                    stringBuilder1.append(s.charAt(i));
                }
            } else {
                if (nums1[s.charAt(i) - 65] == 1) {
                    stringBuilder1.append(s.charAt(i));
                }
            }
        }

        //无序输出
        //stringBuilder转换为String
        String ret = stringBuilder.toString();
        System.out.println(ret);


        //有序输出
        System.out.println(stringBuilder1.toString());
    }

    /***
     * 判断大小写   1为小写    -1为大写
     * @param ch
     * @return
     */
    public static int isCase(char ch) {
        if (ch >= 'a' && ch <= 'z') {
            return 1;
        }
        return -1;
    }


}
